<template>
	<div class="content">
		<div class="clear">
			<Form inline class="fl">
				<Input type="text" placeholder="交易单号" class="w200 m-r10" v-model.trim="query.tradeNum" />
				<Input type="text" placeholder="UUID" class="w200 m-r10" v-model.trim="query.uuid" />
				<Input type="text" placeholder="手机号码" class="w200 m-r10" v-model.trim="query.userName" />
				<Input type="text" placeholder="姓名" class="w200 m-r10" v-model.trim="query.trueName" />
				<DatePicker type="daterange" split-panels placeholder="请选择时间段" class="w200 m-r10" format="yyyy-MM-dd" @on-change="getTime">
				</DatePicker>
				<Button type="primary" v-on:click="getQuery">查询</Button>
			</Form>
		</div>
		<Button class="daochu" type="primary" size="large" @click="exportData" :loading="dcShow">
            <Icon type="ios-download-outline"></Icon> 导出</Button>
		<Table stripe :columns="columns" ref="table" :data='list' :loading="loading"></Table>
		<Page :total="info" show-elevator :page-size="pageSize" show-total @on-change="cuctGetQuery" :current.sync="page"></Page>
	</div>
</template>

<script>
	export default {
		data() {
			return {
				dcShow: false,
				loading: true,
				jsonData: [],
				list: [], // 分享收益列表数据
				info: null, // 总条数
				page: 1, // 页数
				pageSize: 20, // 每页多少条
				current: 1,
				downList: [],
				dataValue: ['', ''], // 时间段值
				query: {
					tradeNum: '',
					uuid: '',
					userName: '',
					trueName: '',
				},
				modal2: false,
				list2: [],
				columns: [{
						title: '交易单号',
						align: 'center',
						key: 'tradeNum',
						render: (h, params) => {
							return h('div', params.row.tradeNum == null ? '#' : params.row.tradeNum)
						}
					},
					{
						title: 'UUID',
						align: 'center',
						key: 'uuid',
						render: (h, params) => {
							return h('div', params.row.uuid == null ? '#' : params.row.uuid)
						}
					},
					{
						title: '交易者姓名',
						align: 'center',
						key: 'trueName',
						render: (h, params) => {
							return h('div', params.row.trueName == null ? '#' : params.row.trueName)
						}
					},
					{
						title: '交易者手机号码',
						align: 'center',
						key: 'userName',
						render: (h, params) => {
							return h('div', params.row.userName == null ? '#' : params.row.userName)
						}
					},
					{
						title: '交易类型',
						align: 'center',
						key: 'tradeType',
						render: (h, params) => {
							return h('div', params.row.tradeType == null ? '#' : params.row.tradeType == 1 ? '买入' : params.row.tradeType == 2 ? '卖出' : '#')
						}
					},
					{
						title: '价格',
						align: 'center',
						key: 'price',
						render: (h, params) => {
							return h('div', params.row.price == null ? '0.00' : this.Fixed(params.row.price))
						}
					},
					{
						title: '花费数量',
						align: 'center',
						key: 'num',
						render: (h, params) => {
							return h('div', params.row.num == null ? '#' : params.row.tradeType == 1 ? this.Fixed(params.row.num) + ' USDT' : params.row.tradeType == 2 ? this.Fixed(params.row.num) + ' ATM' : '#')
						}
					},
					{
						title: '手续费比例',
						align: 'center',
						key: 'ratio',
						render: (h, params) => {
							return h('div', params.row.ratio == null ? '#' : params.row.ratio * 100 + '%')
						}
					},
					{
						title: '手续费',
						align: 'center',
						key: 'fee',
						render: (h, params) => {
							return h('div', params.row.fee == null ? '#' : this.Fixed(params.row.fee) + ' ATM')
						}
					},
					{
						title: '实际得到数量',
						align: 'center',
						key: 'actualNum',
						render: (h, params) => {
							return h('div', params.row.actualNum == null ? '#' : params.row.tradeType == 1 ? this.Fixed(params.row.actualNum) + ' ATM' : params.row.tradeType == 2 ? this.Fixed(params.row.actualNum) + ' USDT' : '#')
						}
					},
					{
						title: '交易状态',
						align: 'center',
						key: 'status',
						render: (h, params) => {
							return h('div', '成功')
						}
					},
					{
						title: '订单时间',
						align: 'center',
						key: 'createTime',
						sortable: true,
						render: (h, params) => {
							return h('div', params.row.createTime == null ? '#' : this.stringToTime(params.row.createTime))
						}
					},
				],
			}
		},
		created() {

		},
		mounted() {
			this.$Message.config({
				top: 250
			})
			this.getQuery() // 查询直推奖励
		},
		methods: {
			exportData() {
				this.jsonData = [];
				this.dcShow = true;
				this.axios.get('/admin/trading/release/statistical', {
					params: {
						current: this.page, // 当前页【可选，默认1】
						size: this.pageSize, // 每页记录数【可选，默认20】
						uuid: this.query.uuid,
						userName: this.query.userName,
						trueName: this.query.trueName,
						startTime: this.dataValue[0] == "" ? "" : this.dataValue[0] + ' 00:00:00',
						endTime: this.dataValue[1] == "" ? "" : this.dataValue[1] + ' 23:59:59'
					}
				}).then(res => {
					if(res.data.code == 200) {
						this.axios.get('/admin/trading/release/statistical', {
							params: {
								current: 1, // 当前页【可选，默认1】
								size: res.data.data.total, // 每页记录数【可选，默认20】
								uuid: this.query.uuid,
								userName: this.query.userName,
								trueName: this.query.trueName,
								startTime: this.dataValue[0] == "" ? "" : this.dataValue[0] + ' 00:00:00',
								endTime: this.dataValue[1] == "" ? "" : this.dataValue[1] + ' 23:59:59'
							}
						}).then(res => {
							if(res.data.code == 200) {
								this.downList = res.data.data.records;
								this.downList.forEach((row, index) => {
									this.downList[index].createTime = this.downList[index].createTime == null ? '#' : this.stringToTime(this.downList[index].createTime);
									this.downList[index].tradeNum = this.downList[index].tradeNum == null ? '#' : this.downList[index].tradeNum;
									this.downList[index].uuid = this.downList[index].uuid == null ? '#' : this.downList[index].uuid;
									this.downList[index].trueName = this.downList[index].trueName == null ? '#' : this.downList[index].trueName;
									this.downList[index].userName = this.downList[index].userName == null ? '#' : this.downList[index].userName;
									this.downList[index].price = this.downList[index].price == null ? '#' : this.Fixed(this.downList[index].price);
									this.downList[index].num = this.downList[index].num == null ? '#' : this.downList[index].tradeType == 1 ? this.Fixed(this.downList[index].num) + ' USDT' : this.downList[index].tradeType == 2 ? this.Fixed(this.downList[index].num) + ' ATM' : '#';
									this.downList[index].ratio = this.downList[index].ratio == null ? '#' : this.downList[index].ratio * 100 + '%';
									this.downList[index].fee = this.downList[index].fee == null ? '#' : this.Fixed(this.downList[index].fee) + ' ATM';
									this.downList[index].actualNum = this.downList[index].actualNum == null ? '#' : this.downList[index].tradeType == 1 ? this.Fixed(this.downList[index].actualNum) + ' ATM' : this.downList[index].tradeType == 2 ? this.Fixed(this.downList[index].actualNum) + ' USDT' : '#';
									this.downList[index].status = '\t成功';
									this.downList[index].tradeType = this.downList[index].tradeType == null ? '#' : this.downList[index].tradeType == 1 ? '买入' : this.downList[index].tradeType == 2 ? '卖出' : '#';

									this.jsonData.push({
										tradeNum: this.downList[index].tradeNum,
										uuid: this.downList[index].uuid,
										trueName: this.downList[index].trueName,
										userName: this.downList[index].userName,
										tradeType: this.downList[index].tradeType,
										price: this.downList[index].price,
										num: this.downList[index].num,
										ratio: this.downList[index].ratio,
										fee: this.downList[index].fee,
										actualNum: this.downList[index].actualNum,
										status: this.downList[index].status,
										createTime: this.downList[index].createTime,
									})
								})
								let str = `交易单号,UUID,交易者姓名,交易者手机号码,交易类型,价格,花费数量,手续费比例,手续费,实际得到数量,交易状态,订单时间\n`;
								this.downLoad(this.jsonData, str, '交易流水');
							}
						})
					}
				})
			},
			// 处理时间段时间格式
			getTime(daterange) {
				this.dataValue = daterange
			},
			getQuery() {
				this.loading = true;
				this.axios.get('/admin/trading/release/statistical', {
					params: {
						current: this.page, // 当前页【可选，默认1】
						size: this.pageSize, // 每页记录数【可选，默认20】
						tradeNum: this.query.tradeNum,
						uuid: this.query.uuid,
						userName: this.query.userName,
						trueName: this.query.trueName,
						startTime: this.dataValue[0] == "" ? "" : this.dataValue[0] + ' 00:00:00',
						endTime: this.dataValue[1] == "" ? "" : this.dataValue[1] + ' 23:59:59'
					}
				}).then(res => {
					if(res.data.code == 200) {
						this.list = res.data.data.records;
						this.info = res.data.data.total;
						this.loading = false;
					}
				})
			},
			cuctGetQuery(page) { // 分页查询直推奖励
				this.loading = true;
				this.axios.get('/admin/trading/release/statistical', {
					params: {
						current: page, // 当前页【可选，默认1】
						size: this.pageSize, // 每页记录数【可选，默认20】
						tradeNum: this.query.tradeNum,
						uuid: this.query.uuid,
						userName: this.query.userName,
						trueName: this.query.trueName,
						startTime: this.dataValue[0] == "" ? "" : this.dataValue[0] + ' 00:00:00',
						endTime: this.dataValue[1] == "" ? "" : this.dataValue[1] + ' 23:59:59'
					}
				}).then(res => {
					if(res.data.code == 200) {
						this.list = res.data.data.records;
						this.info = res.data.data.total;
						this.loading = false;
					}
				})
			},
		}
	}
</script>

<style>

</style>